<?php

// 获取消息列表
// GET msg.volist

namespace app\api\resource\project\msg;
use think\Db;
use think\Session;
use app\api\lib\Page;

class Volist
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['login'];
    // 描述
    public $_description = '获取消息列表';
    // 参数
    public $_param  = [
    ];
    // 返回
    public $_return = [
        200 => '获取成功',
    ];

    public function run(&$request)
    {
        $page = $request->get('page/d',1);
        $show = $request->get('show/d',10);

        $memberId   = Session::get('member.id');
        $memberRole = Session::get('member.role');

        $table = 'project_push';
        if (1 == $memberRole) {
            // 创业者
            $where['from_member_id'] = $memberId;
        } else {
            // 投资人
            $where['to_member_id'] = $memberId;
        }
        $list = Db::name('project_push')->where($where)->order('create_time DESC')->page($page,$show)->select();

        if ( !empty($list) ) {
            foreach ($list as $key => $val) {
                $list[$key]['project'] = Db::name('project')->where('id',$val['project_id'])->find();
            }
        }

        $pagelist = Page::run($table, $page, $show, $where, $list);

        return [200,$pagelist];
    }
}